package com.deloitte.sapnetweaver.command
{
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.deloitte.sapnetweaver.business.AllMasterDelegate;
	import com.deloitte.sapnetweaver.command.BaseGetDataCommand;
	import com.deloitte.sapnetweaver.events.DocumentDetailsEvent;
	import com.deloitte.sapnetweaver.vo.AbstractVO;
	import com.deloitte.sapnetweaver.vo.AllMasterVO;
	import com.deloitte.sapnetweaver.vo.DBMasterVO;
	import com.deloitte.sapnetweaver.vo.DeliverableMasterVO;
	import com.deloitte.sapnetweaver.vo.DocTypeVO;
	import com.deloitte.sapnetweaver.vo.HardwareMasterVO;
	import com.deloitte.sapnetweaver.vo.IconMasterVO;
	import com.deloitte.sapnetweaver.vo.OSMasterVO;
	import com.deloitte.sapnetweaver.vo.ProjectMasterVO;
	import com.deloitte.sapnetweaver.vo.ProjectPhaseVO;
	import com.deloitte.sapnetweaver.vo.SAPSystemMasterVO;
	
	import flash.utils.Dictionary;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.ResultEvent;
	import mx.utils.ObjectUtil;

	public class AllMasterCommand extends BaseGetDataCommand
	{
		private var abstractVO : AbstractVO ;
		private var allMasterVO:AllMasterVO;
		private var dbMasterVO:DBMasterVO;
		private var iconMasterVO:IconMasterVO;
		private var deliverableMasterVO:DeliverableMasterVO;
		private var docTypeVO:DocTypeVO;
		private var hardwareMasterVO:HardwareMasterVO;
		private var osMasterVO:OSMasterVO;
		private var projectMasterVO:ProjectMasterVO;
		private var projectPhaseVO:ProjectPhaseVO;
		private var sapSystemMasterVO:SAPSystemMasterVO;
		
		
		override public  function execute(event:CairngormEvent):void {
			new AllMasterDelegate(this).getAllMasterRecords();
		}
		public override function result(data:Object):void {
			_model.commonModel.allMasterVO = ResultEvent(data).result as AllMasterVO ;
			if(_model.commonModel.allMasterVO != null){
				populateIconMap(_model.commonModel.allMasterVO.iconMasters);
			}
		}
		private function populateIconMap(iconColl:ArrayCollection):void{
			_model.commonModel.documentIconMap = new Dictionary();
			if(iconColl != null && iconColl.length >0){
				for(var i:int=0;i<iconColl.length;i++){
					iconMasterVO = iconColl.getItemAt(i) as IconMasterVO;
					if(iconMasterVO != null){
						_model.commonModel.documentIconMap[iconMasterVO.iconCode] = iconMasterVO.iconFileName;
					}
				}
			}
		}
		
	}
}